﻿using System;
using System.Linq.Expressions;
using Glue.Internals;
using Xunit;

namespace GlueTests.LambdaDecomposerTests
{
    public class When_decomposing
    {
        public class TheClass
        {
            public int AField = 1;
            public String TheProperty { get; set; }
            public decimal AMethod() {return 0; }
            public AnotherClass Nested { get; set; }
        }

        public class AnotherClass
        {
            public int AField = 1;
            public String TheProperty { get; set; }
            public decimal AMethod() { return 0; }
        }

        [Fact]
        public void Should_find_field()
        {
            Expression<Func<TheClass, int>> func = x => x.AField;
            var decomposer = new LambdaDecomposer(func);
            Assert.NotNull(decomposer.GetAccessor());
        }

        [Fact]
        public void Should_find_property()
        {
            Expression<Func<TheClass, String>> func = x => x.TheProperty;
            var decomposer = new LambdaDecomposer(func);
            Assert.NotNull(decomposer.GetAccessor());
        }

        [Fact]
        public void Should_find_method()
        {
            Expression<Func<TheClass, decimal>> func = x => x.AMethod();
            var decomposer = new LambdaDecomposer(func);
            Assert.NotNull(decomposer.GetAccessor());
        }

        [Fact]
        public void Should_find_nested_field()
        {
            Expression<Func<TheClass, int>> func = x => x.Nested.AField;
            var decomposer = new LambdaDecomposer(func);
            Assert.NotNull(decomposer.GetAccessor());
        }

        [Fact]
        public void Should_find_nested_property()
        {
            Expression<Func<TheClass, String>> func = x => x.Nested.TheProperty;
            var decomposer = new LambdaDecomposer(func);
            Assert.NotNull(decomposer.GetAccessor());
        }

        [Fact]
        public void Should_find_nested_method()
        {
            Expression<Func<TheClass, decimal>> func = x => x.Nested.AMethod();
            var decomposer = new LambdaDecomposer(func);
            Assert.NotNull(decomposer.GetAccessor());
        }
    }
}